import wx
import wx.py#This modules gives access to the pyCrust interpreter widget 

try:
    from agw import aui
except ImportError: # if it's not there locally, try the wxPython lib.
    import wx.lib.agw.aui as aui

import environment


selector = None

def _KeyUpEventListener(event): 
	kc = event.GetKeyCode()

	if kc == 126 and event.ControlDown():#` and Control
		environment.s = selector.getCurrSelect()
		event.Skip() 
		pass
	elif kc == 49 and event.ControlDown():#1 and Control
		environment.s1 = selector.getCurrSelect()
		event.Skip() 
		pass
	elif kc == 50 and event.ControlDown():#2 and Control
		environment.s2 = selector.getCurrSelect()
		event.Skip() 
		pass
	elif kc == 51 and event.ControlDown():#3 and Control
		environment.s3 = selector.getCurrSelect()
		event.Skip() 
		pass
	elif kc == 52 and event.ControlDown():#4 and Control
		environment.s4 = selector.getCurrSelect()
		event.Skip() 
		pass
	elif kc == 53 and event.ControlDown():#5 and Control
		environment.s5 = selector.getCurrSelect()
		event.Skip() 
		pass

	elif kc == 126:#`
		environment.sn = selector.getCurrSelectNode()
		event.Skip() 
		pass
	elif kc == 49:#1
		environment.sn1 = selector.getCurrSelectNode()
		event.Skip() 
		pass
	elif kc == 50:#2
		environment.sn2 = selector.getCurrSelectNode()
		event.Skip() 
		pass
	elif kc == 51:#3
		environment.sn3 = selector.getCurrSelectNode()
		event.Skip() 
		pass
	elif kc == 52:#4
		environment.sn4 = selector.getCurrSelectNode()
		event.Skip() 
		pass
	elif kc == 53:#5
		environment.sn5 = selector.getCurrSelectNode()
		event.Skip() 
		pass
	
	pass


def IHelp():
	return """key ` to set select node to e.sn
key 1 to set select node to e.sn1
key 2 to set select node to e.sn2
key 3 to set select node to e.sn3
key 4 to set select node to e.sn4
key 5 to set select node to e.sn5
key ctrl+` to set select object to e.s
key ctrl+1 to set select object to e.s1
key ctrl+2 to set select object to e.s2
key ctrl+3 to set select object to e.s3
key ctrl+4 to set select object to e.s4
key ctrl+5 to set select object to e.s5"""
	
	
def IInit(frame):

	frame.plugins.OgreWindowPlugin.addKeyUpListener(_KeyUpEventListener)
	frame.plugins.SceneTreePlugin.addKeyUpListener(_KeyUpEventListener)

	global selector
	selector = frame.plugins.SceneSelectorPlugin


	pyCrust = wx.py.crust.Crust(frame, -1,size = wx.Size(200,200),style=wx.TR_DEFAULT_STYLE | wx.NO_BORDER)
	#pyCrust.SetMinSize((1,1)) 
	frame.getAuiManager().AddPane(pyCrust, aui.AuiPaneInfo().
						  Name("PyCrust").Caption("PyCrust Pane").
						  Bottom().Layer(1).Position(1).CloseButton(False).MaximizeButton(True).MinimizeButton(True))
	
	pyCrust.IHelp = IHelp
	return pyCrust



